bitkeeper revision 1.1159.269.5 (42386371nvHctvk3SHgDUG4w3o9URw)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Wed, 16 Mar 2005 16:48:49 +0000 (16:48 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Wed, 16 Mar 2005 16:48:49 +0000 (16:48 +0000)
Add support for specifying the interface name to be used by a netif
backend driver instead of the default vifD.N.

Signed-off-by: Mike Wray <mike.wray@hp.com>
linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c
tools/python/xen/lowlevel/xu/xu.c
tools/python/xen/xend/server/netif.py
tools/python/xen/xm/create.py
xen/include/public/io/domain_controller.h

index 9a3eea5932059cf3b74ff6c74ae9f3edf0fcbcf2..f54dd0ad9c92af7c44e9305c25da096f3c0dbd4d 100644 (file)
@@ -119,9 +119,13 @@ void netif_create(netif_be_create_t *create)
     unsigned int       handle = create->netif_handle;
     struct net_device *dev;
     netif_t          **pnetif, *netif;
-    char               name[IFNAMSIZ];
+    char               name[IFNAMSIZ] = {};
 
-    snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
+    if(create->vifname[0] == '\0'){
+        snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
+    } else {
+        snprintf(name, IFNAMSIZ - 1, "%s", create->vifname);
+    }
     dev = alloc_netdev(sizeof(netif_t), name, ether_setup);
     if ( dev == NULL )
     {
index 9a676936830e4057d90fc14d4168d4f2a18e380f..3f32cadc34cb9c98a33390aab0544062d7443fb0 100644 (file)
@@ -259,6 +259,7 @@ static PyTypeObject xu_notifier_type = {
  */
 
 #define TYPE(_x,_y) (((_x)<<8)|(_y))
+
 #define P2C(_struct, _field, _ctype)                                      \
     do {                                                                  \
         PyObject *obj;                                                    \
@@ -279,6 +280,29 @@ static PyTypeObject xu_notifier_type = {
         }                                                                 \
         xum->msg.length = sizeof(_struct);                                \
     } while ( 0 )
+
+/** Set a char[] field in a struct from a Python string.
+ * Can't do this in P2C because of the typing.
+ */
+#define P2CSTRING(_struct, _field)                                        \
+    do {                                                                  \
+        PyObject *obj;                                                    \
+        if ( (obj = PyDict_GetItemString(payload, #_field)) != NULL )     \
+        {                                                                 \
+            if ( PyString_Check(obj) )                                    \
+            {                                                             \
+                _struct * _cobj = (_struct *)&xum->msg.msg[0];            \
+                int _field_n = sizeof(_cobj->_field);                     \
+                memset(_cobj->_field, 0, _field_n);                       \
+                strncpy(_cobj->_field,                                    \
+                        PyString_AsString(obj),                           \
+                        _field_n - 1);                                    \
+                dict_items_parsed++;                                      \
+            }                                                             \
+        }                                                                 \
+        xum->msg.length = sizeof(_struct);                                \
+    } while ( 0 )
+
 #define C2P(_struct, _field, _pytype, _ctype)                             \
     do {                                                                  \
         PyObject *obj = Py ## _pytype ## _From ## _ctype                  \
@@ -456,6 +480,7 @@ static PyObject *xu_message_get_payload(PyObject *self, PyObject *args)
         C2P(netif_be_create_t, domid,        Int, Long);
         C2P(netif_be_create_t, netif_handle, Int, Long);
         C2P(netif_be_create_t, status,       Int, Long);
+        C2P(netif_be_create_t, vifname,      String, String);
         return dict;
     case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY):
         C2P(netif_be_destroy_t, domid,        Int, Long);
@@ -623,6 +648,7 @@ static PyObject *xu_message_new(PyObject *self, PyObject *args)
         P2C(netif_be_create_t, mac[3],       u8);
         P2C(netif_be_create_t, mac[4],       u8);
         P2C(netif_be_create_t, mac[5],       u8);
+        P2CSTRING(netif_be_create_t, vifname);
         break;
     case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY):
         P2C(netif_be_destroy_t, domid,        u32);
index 753ae299724a3a8869ca068c318d76ebc9242850..5afb3df388bfcc676a1a5e41860d856ec544864c 100755 (executable)
@@ -130,7 +130,13 @@ class NetDev(controller.SplitDev):
         self.bridge = None
         self.script = None
         self.ipaddr = []
+        self.vifname = None
 
+        self.vifname = sxp.child_value(config, 'vifname')
+        if self.vifname is None:
+            self.vifname = "vif%d.%d" % (self.controller.dom, self.vif)
+        if len(self.vifname) > 15:
+            raise XendError('invalid vifname: too long: ' + self.vifname)
         mac = self._get_config_mac(config)
         if mac is None:
             raise XendError("invalid mac")
@@ -189,7 +195,9 @@ class NetDev(controller.SplitDev):
         val = ['vif',
                ['idx', self.idx],
                ['vif', vif],
-               ['mac', mac]]
+               ['mac', mac],
+               ['vifname', self.vifname],
+               ]
         if self.bridge:
             val.append(['bridge', self.bridge])
         if self.script:
@@ -207,7 +215,7 @@ class NetDev(controller.SplitDev):
     def get_vifname(self):
         """Get the virtual interface device name.
         """
-        return "vif%d.%d" % (self.controller.dom, self.vif)
+        return self.vifname
 
     def get_mac(self):
         """Get the MAC address as a string.
@@ -267,7 +275,9 @@ class NetDev(controller.SplitDev):
         msg = packMsg('netif_be_create_t',
                       { 'domid'        : self.controller.dom,
                         'netif_handle' : self.vif,
-                        'mac'          : self.mac })
+                        'mac'          : self.mac,
+                        'vifname'      : self.vifname
+                        })
         self.getBackendInterface().writeRequest(msg, response=d)
         return d
 
index 03f815eddb1d0110acc4bb83a501297466c2be51..ae023e49f58800e46b3f41bc729ce660c9eb0255 100644 (file)
@@ -151,7 +151,7 @@ gopts.var('ipaddr', val="IPADDR",
           fn=append_value, default=[],
           use="Add an IP address to the domain.")
 
-gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM",
+gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM,vifname=NAME",
           fn=append_value, default=[],
           use="""Add a network interface with the given MAC address and bridge.
           The vif is configured by calling the given configuration script.
@@ -159,6 +159,8 @@ gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM",
           If bridge is not specified the default bridge is used.
           If script is not specified the default script is used.
           If backend is not specified the default backend driver domain is used.
+          If vifname is not specified the backend virtual interface will have name vifD.N
+          where D is the domain id and N is the interface id.
           This option may be repeated to add more than one vif.
           Specifying vifs will increase the number of interfaces as needed.""")
 
@@ -289,14 +291,18 @@ def configure_vifs(config_devs, vals):
             script = d.get('script')
             backend = d.get('backend')
             ip = d.get('ip')
+            vifname = d.get('vifname')
         else:
             mac = randomMAC()
             bridge = None
             script = None
             backend = None
             ip = None
+            vifname = None
         config_vif = ['vif']
         config_vif.append(['mac', mac])
+        if vifname:
+            config_vif.append(['vifname', vifname])
         if bridge:
             config_vif.append(['bridge', bridge])
         if script:
@@ -383,7 +389,7 @@ def preprocess_vifs(opts, vals):
             (k, v) = b.strip().split('=', 1)
             k = k.strip()
             v = v.strip()
-            if k not in ['mac', 'bridge', 'script', 'backend', 'ip']:
+            if k not in ['mac', 'bridge', 'script', 'backend', 'ip', 'vifname']:
                 opts.err('Invalid vif specifier: ' + vif)
             d[k] = v
         vifs.append(d)
index 61ba2d3776b69cafeb9cd6e0f58c90567e07db5a..c706ab016e5cd3f15c74d8d679a8865b1e8442be 100644 (file)
@@ -477,9 +477,10 @@ typedef struct {
     u32        netif_handle;  /*  4: Domain-specific interface handle.   */
     u8         mac[6];        /*  8 */
     u16        __pad1;        /* 14 */
+    char       vifname[16];   /* 16 */
     /* OUT */
-    u32        status;        /* 16 */
-} PACKED netif_be_create_t; /* 20 bytes */
+    u32        status;        /* 32 */
+} PACKED netif_be_create_t; /* 36 bytes */
 
 /*
  * CMSG_NETIF_BE_DESTROY: